﻿using Gateway.Domain.EFCore.Configuration;
using Gateway.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Gateway.Domain.Configuration;

public class QuestionExtensionCodeConfiguration : EntityConfiguration<QuestionExtensionCode>
{
    public override void Configure(EntityTypeBuilder<QuestionExtensionCode> builder)
    {
        builder.ToTable(t => t.HasComment("试题扩展代码表"));
        builder.Property(x => x.QuestionId).HasMaxLength(36).HasComment("试题标识");
        builder.Property(x => x.QuestionLanguageId).IsRequired().HasMaxLength(36).HasComment("试题语言标识");
        builder.Property(x => x.Code).IsRequired().HasComment("代码");
        builder.Property(x => x.Name).HasMaxLength(500).IsRequired().HasComment("代码的文件名称");
        builder.HasOne(x => x.Language).WithMany(x => x.ExtensionCodes).HasForeignKey(x => x.QuestionLanguageId)
            .OnDelete(DeleteBehavior.Cascade);
        base.Configure(builder);
    }
}